/**
 * 
 */
package com.net.shop.car.manager.ui.personalcenter.jifen;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.JifenGood;
import com.net.shop.car.manager.api.model.Member;
import com.net.shop.car.manager.ui.FullScreenDialog;
import com.net.shop.car.manager.ui.personalcenter.jifen.JifenListView.OnJifenGoodSelectedListener;

/**
 * 积分兑换窗口
 * @author Deve
 *
 */
public class JiFenDuiHuanDialog extends FullScreenDialog implements OnJifenGoodSelectedListener {
	
	/**
	 * 
	 */
	private FrameLayout container;
	
	private View detailView;
	
	/**
	 * 
	 */
	private View jifenList;

	private JifenListView jifenExchangeList;
	private Member user;

	public JiFenDuiHuanDialog(Context context,Member user) {
		super(context, R.style.Dialog_Fullscreen);
		this.user = user;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.personalcenter_jifen);
		initViews();
		
	}

	private void initViews() {
		initTitle(findViewById(R.id.jifen_title),activity.getResources().getString(R.string.personal_jifenduihuan));
		
		findViewById(R.id.title_back_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						onBackPressed();
					}
				});
		
		container = (FrameLayout) findViewById(R.id.jifen_container);
		jifenList = findViewById(R.id.jifen_list);
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		if (jifenExchangeList == null) {
			jifenExchangeList = new JifenListView(activity, jifenList);
			jifenExchangeList.setOnJifenGoodSelectedListener(this);
		}
	}
	@Override
	public void onBackPressed() {
		if (detailView != null) {
			container.removeView(detailView);
			detailView = null;
			container.addView(jifenList);
		} else {
			super.onBackPressed();
		}
	}

	@Override
	public void onJifenGoodSelected(JifenGood jifenGood, int type) {
		if (detailView != null) {
			return;
		}
		detailView = activity.inflater.inflate(R.layout.jifen_detail_item, container, false);
		JiefenDetailView jiefenDetailView = new JiefenDetailView(this,user,detailView);
		jiefenDetailView.setData(jifenGood, type);
		container.removeView(jifenList);
		container.addView(detailView);
	}
}
